package net.zjitc.mapper;

import net.zjitc.pojo.Orders;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;



/**
 * Created by Administrator on 2018/1/3.
 */
public interface OrdersAnnotationMapper {

  //通过id查询订单
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "user_id",property = "user_id"),
            @Result(column = "number",property = "number"),
            @Result(column = "createtime",property = "createtime"),
            @Result(column = "note",property = "note"),
            /**
             * property :user表示实体类对应的列名
             *one:表示一对一的关系
             * select：通过user_id查询用户信息
             */
            @Result(property = "user",column = "user_id",
            one =@One(
                    select = "net.zjitc.mapper.UserMapper.findById",
                    fetchType = FetchType.LAZY
            )
            ),
            /**
             * 查询一对多的关联关系
             */
            @Result(property ="ordersItemList",column = "id",
            many = @Many(
                    select = "net.zjitc.mapper.OrderItemAnnotationMapper.findOrdersItemsByOid",
                    fetchType=FetchType.LAZY
            ))
    })
      Orders findOrdersById( int id);
}
